<%--
  Created by IntelliJ IDEA.
  User: 10475
  Date: 2023/2/23
  Time: 11:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加企业</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
    <script src="${pageContext.request.contextPath}/lib/layui-v2.6.3/layui.js"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<h2>添加企业</h2>

<%--lay-filter="useradmin" id="useradmin"--%>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">***账&nbsp;号：</label>
        <div class="layui-input-inline">
            <input type="text" id="companyId" name="companyId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">***密 码：</label>
        <div class="layui-input-inline">
            <input type="text" id="pwd" name="pwd" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">***公司名：</label>
        <div class="layui-input-inline">
            <input type="text" id="companyName" name="companyName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地&nbsp;址:</label>
        <div class="layui-input-inline">
            <input type="text" id="companyAddress" name="companyAddress" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电&nbsp;话:</label>
        <div class="layui-input-inline">
            <input type="text" id="companyTel" name="companyTel" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮&nbsp;箱:</label>
        <div class="layui-input-inline">
            <input type="text" id="companyEmail" name="companyEmail" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">注册时间:</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" id="addTime" name="addTime" lay-verify="required"  autocomplete="off"  placeholder="yyyy-MM-dd">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">***工商号:</label>
        <div class="layui-input-inline">
            <input type="text" id="gongNum" name="gongNum" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">***状态:</label>
            <div class="layui-input-inline">
                <select name="state" id="state">
                    <option value="正常用户">正常用户</option>
                    <option value="异常用户">异常用户</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="demo1" onclick="submitCompany()">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    function submitCompany() {

        var companyId=$("#companyId").val();
        var companyName=$("#companyName").val();
        var companyAddress=$("#companyAddress").val();
        var companyTel=$("#companyTel").val();
        var companyEmail=$("#companyEmail").val();
        var addTime=$("#addTime").val();
        var gongNum=$("#gongNum").val();
        var state=$("#state").val();
        var pwd=$("#pwd").val();

        if(companyId.length==0||state.length==0||pwd.length==0||companyName.length==0){
            layer.msg('必填项没有填！！请重新填',{icon: 5});
        }else if(companyTel.length!=11){
            layer.msg('电话填写有误',{icon: 5});
        }else  if (!new RegExp("^([a-zA-Z]|[0-9])(\\w|\\-)+@[a-zA-Z0-9]+\\.([a-zA-Z]{2,4})$").test(companyEmail)) {
            layer.msg('邮箱格式有误，请重新填写',{icon: 5});
        }
        else{
            console.log(state);

            $.ajax({
                url: "${pageContext.request.contextPath}/AddCompany",
                type: 'post',
                dataType: 'text',
                data: {
                    'companyId':companyId,
                    'companyName':companyName,
                    'companyAddress':companyAddress,
                    'companyTel':companyTel,
                    'companyEmail':companyEmail,
                    'addTime':addTime,
                    'gongNum':gongNum,
                    'state':state,
                    'pwd':pwd,
                },
                success: function (res) {
                    if("success"==res) {
                        alert("添加成功");
                    }else{
                        alert("添加失败,该账号已被录用！！！");
                    }
                },
                error: function (res) {
                    alert("添加失败,该账号已被录用！！！");
                }
            });
        }


    }
</script>
<script>
    layui.use('form', function(){
        var form = layui.form;

    });
</script>

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#addTime'
        });
    });
</script>
</html>
